In interviews, young programmers are asked for a real-world scenario explaining OOP and many fail to answer. This is the reason I am writing this article. This article is mainly intended for the audience who knows the Object Oriented Programming (OOP) concept theoretically but is unable to link it with the real world & programming world.

We write programs to solve our problems and get our work done.
Object Oriented Programming is considered as a design methodology for building non-rigid software. In OOPS, every logic is written to get our work done but represented in the form of Objects. OOP allows us to break our problems into small units of work that are represented via objects and their functions. We build functions around objects.
Four features of OOP
There are mainly four pillars (features) of OOP. If all of these four features are presented in programming, the programming is called Object Oriented Programming.
- Abstraction
- Encapsulation
- Inheritance
- Polymorphism
Let's consider an example explaining each of these pillars so you can better understand Object Oriented Programming.
Before that, we need to know something.
When we think of a mobile phone as an object, the basic functionality for which it was invented were Calling & Receiving a call & Messaging. But nowadays thousands of new features and models have been added and the features and number of models are still growing.


In the above diagram, each brand (Samsung, Nokia, iPhone) has its list of features along with basic functionality of dialing, receiving a call, and messaging.
Objects
Any real-world entity which can have some characteristics or which can perform some tasks is called an Object. This object is also called an instance i.e. a copy of an entity in a programming language. If we consider the above example, a mobile manufacturing company can be an object. Each object can be different based on its characteristics. For example, here are two objects.
Mobile mbl1 = new Mobile();
Mobile mbl2 = new Mobile();
Class
A class in OOP is a plan which describes the object. We call it a blueprint of how the object should be represented. Mainly a class would consist of a name, attributes, and operations. Considering the above example, the Mobile can be a class, that has some attributes like Profile Type, IMEI Number, Processor, and some more. It can have operations like Dial, Receive, and SendMessage.
Some OOPS principles need to be satisfied while creating a class. This principle is called SOLID where each letter has some specification. I won't be going into these points deeper. A single line of each explanation may clear you with some points.
- SRP (The Single Responsibility Principle): A class should have one, and only one responsibility
- OCP (The Open Closed Principle): You should be able to extend a class's behavior, without modifying it. (Inheritance)
- LSP (The Liskov Substitution Principle): Derived classes must be substitutable for their base classes. (Polymorphism)
- ISP (The Interface Segregation Principle): Make a finely chopped interface instead of a huge interface as clients cannot be forced to implement an interface that they don't use.
- DIP (The Dependency Inversion Principle): Depend on abstractions, not on concretions. (Abstraction)
If you want to learn more about SOLID principles, check out SOLID Architectural Pattern with Real World Example.
Now, let's take a look at our class. A typical class based on the above discussion looks like the following in Visual Studio:

In C# programming language, a class has members. These members are called properties, methods, fields, constructors, destructors, events, and so on.
In code, the Mobile class looks like the following.
public class Mobile
{
private string IEMICode { get; set; }
public string SIMCard { get; set; }
public string Processor { get; }
public int InternalMemory { get; }
public bool IsSingleSIM { get; set; }
public void GetIEMICode()
{
Console.WriteLine("IEMI Code - IEDF34343435235");
}
public void Dial()
{
Console.WriteLine("Dial a number");
}
public void Receive()
{
Console.WriteLine("Receive a call");
}
public virtual void SendMessage()
{
Console.WriteLine("Message Sent");
}
}
Abstraction
Abstraction allows us to expose limited data and functionality of objects publicly and hide the actual implementation. It is the most important pillar in OOPS. In our example of Mobile class and objects like Nokia, Samsung, and iPhone.
Some features of mobiles
- Dialing a number calls some method internally that concatenates the numbers and displays it on screen but what is it doing we don’t know.
- Clicking on the green button sends signals to the calling person's mobile but we are unaware of how it is doing.
This is called abstraction. In classes, we can create methods that can be called and used by the users of the class but users will have no idea what these methods do internally.
public void Dial()
{
//Write the logic
Console.WriteLine("Dial a number");
}
Encapsulation

Encapsulation is defined as the process of enclosing one or more details from the outside world through access rights. It says how much access should be given to particular details. Both Abstraction & Encapsulation work hand in hand because Abstraction says what details are to be made visible and Encapsulation provides the level of access right to that visible details. i.e. – It implements the desired level of abstraction.
Talking about Bluetooth which we usually have in our mobile. When we switch on Bluetooth, I can connect to another mobile or Bluetooth-enabled device but I'm not able to access the other mobile features like dialing a number, accessing inbox, etc. This is because the Bluetooth feature is given some level of abstraction.
Another point is when mobile A is connected with mobile B via Bluetooth whereas mobile B is already connected to mobile C then A is not allowed to connect to C via B. This is because of accessibility restrictions.
In C#, a class has access modifiers such as public, private, protected, and internal. These access modifiers allow properties and methods to be exposed or restricted to the outside world.
private string IMEICode = "76567556757656";
Polymorphism
Polymorphism can be defined as the ability to use the same name for doing different things. More precisely we say it as 'many forms of single entity'. This plays a vital role in the concept of OOPS.
Let's say Samsung mobile has a 5MP camera available i.e. – it is having the functionality of CameraClick(). Now the same mobile has Panorama mode available in the camera, so functionality would be the same but with mode. This type is said to be Static polymorphism or Compile-time polymorphism. See the example below.
public class Samsumg : Mobile
{
public void GetWIFIConnection()
{
Console.WriteLine("WIFI connected");
}
//This is one mwthod which shows camera functionality
public void CameraClick()
{
Console.WriteLine("Camera clicked");
}
//This is one overloaded method which shows camera functionality as well but with its camera's different mode(panaroma)
public void CameraClick(string CameraMode)
{
Console.WriteLine("Camera clicked in " + CameraMode + " Mode");
}
}
Compile time polymorphism the compiler knows which overloaded method it is going to call.
The compiler checks the type and number of parameters passed to the method and decides which method to call and it will give an error if there are no methods that match the method signature of the method that is called at compile time.
Another point where that SendMessage was intended to send a message to a single person at a time but suppose Nokia had given provision for sending a message to a group at once. i.e. - Overriding the functionality to send a message to a group. This type is called Dynamic polymorphism or Runtime polymorphism.
For overriding you need to set the method, which can be overridden to virtual & its new implementation should be decorated with the override keyword.
public class Nokia : Mobile
{
public void GetBlueToothConnection()
{
Console.WriteLine("Bluetooth connected");
}
//New implementation for this method which was available in Mobile Class
//This is runtime polymorphism
public override void SendMessage()
{
Console.WriteLine("Message Sent to a group");
}
}
By runtime polymorphism, we can point to any derived class from the object of the base class at runtime that shows the ability of runtime binding.
Inheritance

Inheritance is the ability to extend the functionality from the base entity to a new entity belonging to the same group. This will help us to reuse the functionality that was already defined before and extend it into a new entity.
Considering the example, the above figure 1.1 itself shows what is inheritance. Basic Mobile functionality is to send a message, dial, and receive a call. So the brands of mobile are using this basic functionality by extending the mobile class functionality and adding new features to their respective brand.
Four types of inheritance
There are mainly 4 types of inheritance,
- Single level inheritance
- Multi-level inheritance
- Hierarchical inheritance
- Hybrid inheritance
- Multiple inheritance
Single level inheritance
In Single-level inheritance, there is a single base class & a single derived class i.e. - A base mobile feature is extended by the Samsung brand.

Multilevel inheritance
In Multilevel inheritance, there is more than one single level of derivation. i.e. - After base features are extended by the Samsung brand. Now Samsung brand has manufactured its new model with newly added features or advanced OS like Android OS, v4.4.2 (KitKat). From generalization, getting into more specification.

Hierarchal inheritance
In this type of inheritance, multiple derived classes would be extended from a base class, it's similar to single-level inheritance but this time along with Samsung, Nokia is also taking part in inheritance.

Hybrid inheritance
Single, Multilevel, & hierarchal inheritance all together construct a hybrid inheritance.

public class Mobile
{
//Properties
//Methods
}
public class Samsumg : Mobile
{
//Properties
//Methods
}
public class Nokia : Mobile
{
//Properties
//Methods
}
Interface
Multiple inheritance where derived class will extend from multiple base classes.
Samsung will use the function of multiple Phones (Mobile & Telephone). This would create confusion for the compiler to understand which function to call when any event in mobile is triggered like Dial () where Dial is available in both the Phone i.e. - (Mobile & Telephone). To avoid this confusion C# came up with the concept of interface which is different from multiple inheritance.
If we take an interface it is similar to a class but without implementation & only declaration of properties, methods, delegates & events. The interface enforces the class to have a standard contract to provide all implementation to the interface members. Then what is the use of an interface when they do not have any implementation? The answer is, that they help have readymade contracts, only we need to implement functionality over this contract.
I mean to say, Dial would remain Dial in the case of Mobile or Telephone. It won't be fair if we give different names when the task is to Call the person.
The interface is defined with the keyword 'interface'.All properties & methods within the interface should be implemented if it is been used. That's the rule of interface.

interface IMobile
{
void Dial();
}
interface ITelephone
{
void Dial();
}
public class Mobile : IMobile, ITelephone
{
public void Dial()
{
Console.WriteLine("Dial a number");
}
}
Conclusion
Following the above principle and keeping in mind the four pillars of OOPS will lead you to develop a good program and connect it with the real world. I hope you like this article. Don't forget to share your comment whether it's good or bad. Sharing is valuable no matter what.
Download the file for the same code.
Reference
Mayooran NavamanyPosted Sep 28, 2022, 1:56 AM
Nice article..
Naresh. gPosted Sep 26, 2022, 5:37 PM
Can you please help me to download the same
Naresh. gPosted Sep 26, 2022, 5:37 PM
Not able to download the zip file
Hammad AhmedPosted May 30, 2021, 7:42 PM
This was very helpful. where can i get the code for this file?
Indra vermaPosted Apr 15, 2021, 7:26 PM
Nice article...
ravi kumarPosted Apr 5, 2021, 12:05 PM
Its good article.....
Angela LeePosted Jun 29, 2020, 11:24 PM
Never seen a real-time example like this one before, this is amazing, I wish I read this article 4 years ago to understand OOP much better.
shital jadhavPosted Oct 17, 2019, 4:40 AM
Explained very nice manner with real life example Mobile.
prabhat kumarPosted May 1, 2019, 5:15 AM
Nice Real Time example it help alot...Thanks
priti sumaniPosted Oct 7, 2018, 1:24 PM
Nice and detail Explanation
Bikash AdhikariPosted Sep 14, 2018, 11:35 AM
Incredible explanation with simplicity.
Mohammed IsmailPosted Aug 24, 2018, 1:03 AM
Very good and simple explanation...Thanks
soma sundaramPosted Jul 9, 2018, 7:21 AM
Nice article..
Seshu BPosted Jul 2, 2018, 8:54 AM
Nice Explanation..
Akanksha singhPosted Jun 14, 2018, 4:52 AM
Good article. Very helpful
Amol KumbhkarnaPosted May 6, 2018, 2:15 AM
You made my day bro... Sweet and simple article on OOPS..!!!! Keep It Up ...!!!
Akshata AbhyankarPosted May 4, 2018, 5:18 AM
Very useful article with real world example..thanks
sukesha kambliPosted Mar 4, 2018, 1:23 PM
Will you explain with the help of Diagram*... what is the difference between Hierarchical, Multiple Inheritance, and Interface? your example(Mobile) is very much understandable Thank You so much
Sunny shrivastavPosted Jan 8, 2018, 1:36 PM
Thanks brother...Well done...
Colin MoldPosted Dec 1, 2017, 5:15 AM
Thanks for this excellent article Pradeep. Very clear and concise.
Nithish ReddyPosted Nov 14, 2017, 3:51 AM
Superb Description Bro !
Nauman ShafiquePosted Oct 25, 2017, 10:13 AM
Excellent Bro :) much easier to digest all OOP from a single page .Thumbs Up
vishnu jutlaPosted Jul 15, 2017, 11:37 AM
Very good article on oops concepts. i was looking for something like this which explains oops concepts with real time objects.
pramod kumarPosted Jul 4, 2017, 2:23 AM
Very helpful article
abhishek singhPosted Jun 14, 2017, 2:21 PM
Its really very helpful to me...thanks pradeep shet
kinjal patelPosted Jan 30, 2017, 6:25 AM
I think it was good article. later i read your post but thanks in advanced
Mahadevan AnnamalaiPosted Jan 15, 2017, 8:16 PM
Very helpful article.. thanks for the post
Adewale AdeleyePosted Sep 22, 2016, 8:47 AM
Can we say that class X(object): inherits from class object?
Mayooran NavamanyPosted Sep 7, 2016, 4:20 AM
Very helpful for me ...thank a lot Pradeep Shet
veera muthuPosted Aug 3, 2016, 6:06 AM
Nice one. Thankyou Pradeep.
Sanjeev PundirPosted Jul 25, 2016, 8:59 AM
Best article..... I face this situation in interview .... its really Very helpful for me ...thank a lot ....
Arvind SharmaPosted Jul 23, 2016, 8:04 AM
This is the best explanation of OOPS concept I ever learned. Its very clear and well explained for anybody to undersatand .Thanks Pradeep. Keeps posting such articles.
Dipu ParmarPosted Jun 2, 2016, 8:01 AM
its really helpful for me ...thank you....
sameer shaikhPosted May 30, 2016, 5:32 AM
very useful to fresher guys..
patel ghanashyamPosted May 10, 2016, 2:38 AM
very useful and good explanation ..................with real world example
Raj Kumar SepatPosted May 6, 2016, 3:25 AM
Good Job Pradeep ,Awesome Article with Real Life Example
Thiruppathi RPosted Apr 29, 2016, 5:25 AM
Good Job
Hari ShankerPosted Apr 29, 2016, 2:41 AM
Great Wok Pradeep Shet
Prakash ChasiyaPosted Mar 7, 2016, 1:41 AM
Very nice article with good explanation... Thanks :)
Rahul GuptaPosted Mar 4, 2016, 2:18 AM
Nice Work Buddy....Keep it up...Thanks...:)
Vipan SharmaPosted Feb 16, 2016, 2:29 AM
Great. Nice work done by you.
Amit Kumar SinghPosted Feb 6, 2016, 7:17 AM
Nice One
priya sharmaPosted Jan 20, 2016, 7:50 AM
Nice tutorial.. but unable to open file in 2008 framework.. version issue..
Pramod GayakwadPosted Jan 19, 2016, 1:07 AM
Great it clears my all doubts
Tetali RadhaKrishnaPosted Dec 24, 2015, 1:56 AM
thank you ..
Uday Bhan SinghPosted Oct 23, 2015, 1:33 AM
Very helpful oops concept thanks i hope you help me another time also
Gopi ChandPosted Oct 13, 2015, 11:23 AM
Worthy
Sujeet SumanPosted Oct 9, 2015, 8:11 AM
Nice Article.................
ASMA BATOOL LPosted Sep 15, 2015, 12:05 PM
Nice article with clear explanation
Pramod KharviPosted Sep 10, 2015, 11:16 PM
Bro hats off to your article nice job bro. But if u could justify the same example with program it would be helpful
Bharat TakePosted Sep 10, 2015, 7:27 AM
Good Article.i Read All Carefully but i want one more.Can you Work on SOLID Design Pattern Article.Please give me.
Latha RPosted Sep 8, 2015, 8:10 AM
Apt explanation of the concept. Thank you
MathiPosted Sep 3, 2015, 9:49 AM
Unable to open the downloaded file MobileEx.zip
vikash vermaPosted Aug 29, 2015, 1:51 PM
great it clears my all doubts
mohan dassPosted Aug 25, 2015, 9:12 AM
Thank u
kamal chandraPosted Aug 11, 2015, 6:41 PM
Thanks ...
shwetha jPosted Aug 2, 2015, 2:05 PM
Awesome article u explained so nicely with real time scenario thanks a lot
hemanth gorurPosted Jul 28, 2015, 7:10 AM
Very nice article. But I am not able to download it.
venkat ramanaPosted Jul 14, 2015, 10:13 AM
Very nice article.Thank you
Rahul SutarPosted Jul 7, 2015, 10:56 AM
Very nice article with real time examples....Thanks
Vikramraj PatilPosted Jul 1, 2015, 9:25 AM
Simple and Clean Explanation......
Saroj Kumar SahuPosted Jun 26, 2015, 1:06 AM
Very good explanation..Thanks
Edrick LomibaoPosted Jun 22, 2015, 10:03 PM
Thanks Pradeep Shet nice article.
Sibeesh VenuPosted Jun 22, 2015, 5:00 AM
Good One.
Debendra DashPosted Jun 22, 2015, 4:52 AM
nicely explained........
Dinesh BeniwalPosted Jun 22, 2015, 4:22 AM
Thanks for sharing ;)
Gopi ChandPosted Jun 22, 2015, 3:04 AM
Well done :)
VINAY KUMAR GUPTAPosted Jun 14, 2015, 8:54 AM
Excellent article i don't have word to explain more thanks a lots
rajesh bhattPosted Jun 10, 2015, 9:50 AM
One of the best article I have read on oops concept.Thanks.
Sandeep BhoitePosted Jun 2, 2015, 1:54 PM
thanks very nice and useful material
Gowtham RajamanickamPosted May 20, 2015, 1:24 AM
good one
Chandran MahalingamPosted Feb 27, 2015, 8:33 AM
nice explanation bro... keep it up..
vivek patelPosted Feb 15, 2015, 10:26 AM
Buddy Good Explain...
SudhanshuPosted Feb 12, 2015, 9:26 PM
The way you explained the things is good
Kunal KhairnarPosted Feb 9, 2015, 1:58 PM
Very Good Article...Thanks...
Lucky LaxmanPosted Feb 5, 2015, 8:27 AM
Nice Explained . But when i use abstract class abstract method why use this is only, and virtual Method example,how to use sealed class what is use of sealed class?. once use sealed class what will happen ?.
Muralitharan APosted Jan 5, 2015, 8:26 AM
Kudos to you..Excellent article!!! Keep up the Good Work
Jitendra KumarPosted Dec 7, 2014, 11:07 PM
good article..
Vithal WadjePosted Dec 7, 2014, 10:52 PM
outstanding keep it up
Vitthal RandivePosted Nov 17, 2014, 2:03 AM
Thanks for sharing this article , It is nice article .
Karen TonoyanPosted Aug 22, 2014, 8:02 AM
Nice
aavishkar paranjapePosted Jun 7, 2014, 8:17 AM
good one !!
Pranali KshatriyaPosted May 11, 2014, 7:43 AM
Nicely explained.Thank you Sir
Vipin TyagiPosted May 9, 2014, 8:18 PM
Good Article